﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CodeTier.BUL;

namespace Source.ViewModels
{
    public class CartShop
    {
        public List<CartLine> ds_cart { get; set; }
        public decimal total { get; set; }

        public CartShop()
        {
            ds_cart = new List<CartLine>();
            total = 0;
        }

        public void addItem(SanPhamBUS sp , int sl)
        {
            CartLine cartline = new CartLine(sp, sl);
            this.ds_cart.Add(cartline);
            total += cartline.Gia;
        }

        public void removeItem(CartLine cartline)
        {
            total -= cartline.Gia;
            ds_cart.Remove(cartline);
        }

    }

    public class CartLine
    {
        public SanPhamBUS sp { get; set; }
        public int SL { get; set; }
        public decimal Gia { get; set; }

        public CartLine(SanPhamBUS sp, int sl)
        {
            this.sp = sp;
            this.SL = sl;
            this.Gia = sp.DonGia * sl;
        }

        public void addSL(int sl)
        {
            this.SL +=sl;
            Gia = sp.DonGia * this.SL;
        }
    }
}